// pages/reportEvaluate/reportEvaluate.js
var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    display: "none",
    display_1: "none",
    display_2: "none",
    display_3: "none",
    display_4: "none",
    display_5: "none",
    num_: 0,
    pics:[],
    onload: "block",
    src:"../image/no_name.png",
    src_:"../image/selectchose_03.png",
    isSelect:false,
    text:""
  },
  //表单提交
  show_payment:function(){
    let that = this;
    var pic='';
    var i=0;
    for (i=0;i<that.data.pics.length;i++){
      pic = that.data.pics[i] +'_-_'+pic
    }
    var sum_grade = that.data.xing;
    var content = that.data.text;
    var ogid=that.data.goods.ogid
    wx.request({
      url: app.data.Url +'comment/commentdata',
      data:{
        sum_grade: sum_grade,
        content: content,
        ogid: ogid,
        pics:pic,
        uid:wx.getStorageSync('userInfo').uid
      },
      method:'post',
      success:function(res){
          if(res.data.code==1){
            wx.showModal({
              title: '提示',
              content: '评论成功',
              success:function(){
                wx.navigateBack({
                  
                })
              }
            })
          }
      }
    })
  },
  deleteList(e) {
    const index = e.currentTarget.dataset.index;
    let pics = this.data.pics;
    pics.splice(index, 1);
    this.setData({
      pics: pics
    });
    if (pics.length < 3) {
      console.log(pics.length)
      this.setData({
        onload: "block",
      });
    }
  },
  gotoShow: function () {//这里是选取图片的方法
    var that = this;
    var pics = this.data.pics;
    wx.chooseImage({
      count: 1, // 最多可以选择的图片张数，默认9
      sizeType: ['original', 'compressed'], // original 原图，compressed 压缩图，默认二者都有
      sourceType: ['album', 'camera'], // album 从相册选图，camera 使用相机，默认二者都有
      success: function (res) {
      wx.showLoading({
        title: '上传中',
      })
        wx.uploadFile({
          url: app.data.Url+'spell/upload',
          filePath: res.tempFilePaths[0],
          name: 'image',
          header: { "Content-Type": "multipart/form-data" },
          success:function(e){
           
            if (pics.length < 3){
              that.setData({
                onload: "",
              });
              console.log(JSON.parse(e.data).img);
              pics.push(JSON.parse(e.data).img)
              that.setData({
                pics: pics
              })
            }else{
              wx.hideLoading();
              that.setData({
                onload: "none",
              });
              return false;
            }
            wx.hideLoading();
          }
        })
        // var imgsrc = res.tempFilePaths;
        // if (pics.length < 3) {
        //   pics = pics.concat(imgsrc);
        // }
        // else {
        //   return false
        // }
        // that.setData({
        //   pics: pics
        // });
        // if (pics.length == 3) {
        //   console.log(pics.length)
         
        // }
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })

  },
  show_name: function (e) {
    if (e.target.dataset.num == 0) {
      this.setData({
        src: "../image/selectchose_03.png",
        num_: 1,
        isSelect:true
      })
    }
    if (e.target.dataset.num == 1) {
      this.setData({
        src: "../image/no_name.png",
        num_: 0,
        isSelect: false
      })
    }
    console.log(this.data.isSelect)
  },
  //显示选中星星
  show_this: function (e) {
    var that=this;
    if (e.target.dataset.num == 1) {
      this.setData({
        display_1: "block"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
    if (e.target.dataset.num == 2) {
      this.setData({
        display_1: "block",
        display_2: "block"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
    if (e.target.dataset.num == 3) {
      this.setData({
        display_1: "block",
        display_2: "block",
        display_3: "block"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
    if (e.target.dataset.num == 4) {
      this.setData({
        display_1: "block",
        display_2: "block",
        display_3: "block",
        display_4: "block"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
    if (e.target.dataset.num == 5) {
      this.setData({
        display_1: "block",
        display_2: "block",
        display_3: "block",
        display_4: "block",
        display_5: "block"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
    console.log(e.target.dataset.num)
  },
  //取消选中星星
  hide_this: function (e) {
    var that=this;
    if (e.target.dataset.num == 5) {
      this.setData({
        display_1: "block",
        display_2: "block",
        display_3: "block",
        display_4: "block",
        display_5: "block"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
    if (e.target.dataset.num == 4) {
      this.setData({
        display_5: "none"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
    if (e.target.dataset.num == 3) {
      this.setData({
        display_4: "none",
        display_5: "none"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
    if (e.target.dataset.num == 2) {
      this.setData({
        display_3: "none",
        display_4: "none",
        display_5: "none"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
    if (e.target.dataset.num == 1) {
      this.setData({
        display_2: "none",
        display_3: "none",
        display_4: "none",
        display_5: "none"
      })
      that.setData({
        xing: e.target.dataset.num
      })
    };
  },
  //获取评论内容
  text:function(e){
    this.setData({
      text: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    wx.request({
      url: app.data.Url +'Spell/getOgid',
      data:{
        orderid:options.orderid
      },
      success:function(res){
      that.setData({
        goods: res.data.data
      })
      }
    })
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})